home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Internet Info 1994 March
/
Internet Info CD-ROM (Walnut Creek) (March 1994).iso
/
networking
/
ip
/
ka9q
/
xobbs.arc
/
xocommon.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-05-03
|
6KB
|
299 lines
/* XOCOMMON.C Commonly used routines for XOBBS and MAILDAEMON.*/
/* Jim Durham, W2XO 10-24-88 */
/* Version 1.0 */
/* Code released to the amateur radio community */
#include "xobbs.h"
prinout(mode)
int mode; /*modes - FLUSH/NOFLUSH */
{
char *cp;
int i,j;
static char buf[1024]; /*and buffer*/
static int bufcnt = 0;
if(local){
cp=prinbuf;
while(*cp){
write(outfd,cp++,1);
}
alarm(180);
}
else{
alarm(500);
j=strlen(prinbuf); /*get length of new output*/
for(i=0;i < j;i++){ /*convert lfs to crs*/
if(prinbuf[i] == '\n')
prinbuf[i] = '\r';
}
sprintf(buf + bufcnt,"%s",prinbuf); /*copy prinbuf to output buffer*/
for(i=0; i < j; i++) /*zero out prinbuf*/
prinbuf[i] = '\0';
/*if buffer full or mode is FLUSH*/
bufcnt = strlen(buf);
if((bufcnt + j) > 254)
mode = FLUSH; /*force a buffer flush if full*/
if(mode == FLUSH){ /*flush the buffer*/
sprintf(msg.mtext,"%s",buf); /*fill the message text area*/
msg.mtype = (long)pid; /*source address (bbs pid)*/
if((msgsnd(smsgqid,&msg,bufcnt,0600)) < 0) /*send the output*/
perror("prinout:"); /*barf if error*/
bufcnt = 0; /*buffer flushed, zero count*/
}
}
}
cprinout()
{
int i,j;
if(local){
perror("cprintout called from local\n");
return;
}
j=strlen(prinbuf);
for(i=0;i < j;i++){
if(prinbuf[i] == '\n') /*convert lfs to crs */
prinbuf[i] = '\r';
}
sprintf(msg.mtext,"%s",prinbuf); /*fill the message text area*/
msg.mtype = (long)pid;
if((msgsnd(scmsgqid,&msg,j,0600)) < 0)
perror("xocommon001");
for(i=0; i < strlen(prinbuf); i++)
prinbuf[i] = '\0';
}
sndupkil()
{
if(local){
sprintf(prinbuf,"\n");
prinout(FLUSH);
exit(0);
}
else{
sprintf(msg.mtext,"K\0");
msg.mtype = (long)pid;
if(msgsnd(scmsgqid,&msg,strlen(msg.mtext),0600) < 0)
perror("sndupkil:"); /*send kill*/
for(;;); /*wait for kill*/
}
}
gethighnum(flag)
int flag;
{
int fd;
char temp[30];
if((fd=open(paramfil,O_RDONLY)) < 0){
if(flag){
perror("maildaemon:paramfil:");
exit(1);
}
else{
sprintf(prinbuf,"bbs:Cant open %s\n",paramfil);
perror(prinbuf);
sndupkil();
for(;;);
}
}
read(fd,temp,6);
temp[6]='\0';
highnum=atoi(temp);
read(fd,temp,6);
temp[6]='\0';
msgcnt=atoi(temp);
}
getconfig()
{
int fd;
strcpy(homedir,HOMEDIR);
sprintf(prinbuf,"%sconfig.xo",homedir);
if((fd=open(prinbuf,O_RDONLY)) < 0){
perror("getconfig:Cant open config file");
exit(1);
}
fgetline(fd,inline); /*forwarding file*/
rdfield(inline,fwddist);
fgetline(fd,inline);
rdfield(inline,fwddir);
fgetline(fd,inline); /*get a line from the config file*/
rdfield(inline,maildir); /*read the first field of file line*/
fgetline(fd,inline); /*get next file line*/
rdfield(inline,filedir); /*read first field to file path*/
fgetline(fd,inline); /*..and so on */
rdfield(inline,tempdir);
fgetline(fd,inline); /*..and so on */
rdfield(inline,usenetfil); /* usenet file directory*/
fgetline(fd,inline);
rdfield(inline,paramfil);
fgetline(fd,inline);
rdfield(inline,fwdfile);
fgetline(fd,inline);
rdfield(inline,motdfil);
fgetline(fd,inline);
rdfield(inline,maildae);
fgetline(fd,inline);
rdfield(inline,userfil);
fgetline(fd,inline);
rdfield(inline,hdrfile);
fgetline(fd,inline);
rdfield(inline,logfile);
fgetline(fd,inline);
rdfield(inline,my.call);
fgetline(fd,inline);
rdfield(inline,my.name);
fgetline(fd,inline);
rdfield(inline,my.qth);
close(fd);
}
rdfield(s,t)
char *s,*t;
{
while((((*t = *s) != ' ') && (*s != '\t')) && ((*s != '\n') && (*s != '\0'))){
t++;
s++;
}
*t='\0';
}
fputline(fd,s)
int fd;
char *s;
{
static char c = '\n';
write(fd,s,strlen(s));
write(fd,&c,1);
}
fgetline(fd,s)
int fd;
char *s;
{
int i;
char c;
i=0;
while((c=xogetc(fd)) && ((c != '\n') && (c != '\r')))
s[i++] = c;
s[i] = '\0';
return(i);
}
char xogetc(fd)
{
char c;
if(read(fd,&c,1)){
c &= (char)0x7f; /*strip 8th bit and up*/
if(c=='\r')
c='\n';
return(c);
}
else return('\0');
}
conhdr(hdr,mhdr) /*convert a header to header struct*/
char *hdr;
struct msghdr *mhdr;
{
char temp[20];
rdfield(hdr,temp);
mhdr->siz=atoi(temp);
mhdr->type=hdr[6];
mhdr->stat=hdr[7];
rdfield(&hdr[9],mhdr->tocall);
rdfield(&hdr[16],mhdr->fromcall);
rdfield(&hdr[23],mhdr->atbbs);
rdfield(&hdr[30],mhdr->dat);
rdfield(&hdr[37],mhdr->tim);
strncpy(mhdr->title,&hdr[42],30);
mhdr->title[30] = '\0';
rdfield(&hdr[73],mhdr->bid);
}
matchn2(cp,lp,n)
char *cp;
char *lp;
int n;
{
int i,except;
if(n == 0)
return false;
except=0;
if(*cp=='!')
{
except=1;
cp++;
}
if(*lp=='!')
{
except=1;
lp++;
}
for(i=0;i<n;i++)
{
if((*cp == *lp) || ((*cp=='?') || (*lp=='?')))
{
cp++;
lp++;
if((*cp=='\0') || (*lp == '\0'))
if(except) return(false); else return(true);
if((*cp=='*') || (*lp=='*')) /*if the first char*/
if(except) return(false); else return(true); /* is a star*/
}
else
if(except) return(true); else return(false);
}
if(except) return(false); else return(true);
}
char *upcase(stng) /*W2XO 8-11-87*/
char *stng;
{
char *strpnt;
strpnt=stng;
do
*strpnt = islower(*strpnt) ? toupper(*strpnt) : *strpnt;
while(*strpnt++);
return(stng); /*return the original string*/
}
char *lowcase(stng) /*W2XO 8-11-87*/
char *stng;
{
char *strpnt;
strpnt=stng;
do
*strpnt = isupper(*strpnt) ? tolower(*strpnt) : *strpnt;
while(*strpnt++);
return(stng); /*return the original string*/
}